<%--
  Created by IntelliJ IDEA.
  User: dqf
  Date: 2015/3/9
  Time: 15:16
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<div class="row">
    <div class="col-xs-12 col-sm-7 col-md-7 col-lg-4">
        <h1 class="page-title txt-color-blueDark" style="margin-top:6px;margin-bottom:10px">
            <i class="fa fa-table fa-fw "></i>
            分享信息
        </h1>
    </div>
</div>

<div id="business_data">
    <div class="row" style="padding:2px;padding-bottom: 5px">
        <div class="col-sm-12 col-md-12 col-lg-12">
            <div >
                <form id="searchForm" method="post" action="">
                    <shiro:hasAnyRoles name="wechat">
                    <a id="ajax_knowledge_btn_add" class="btn btn-default " data-toggle="modal"><i class="fa fa-lg fa-plus"></i> 新建共享信息</a>
                    </shiro:hasAnyRoles>
                </form>
            </div>
        </div>
    </div>
    <!-- rows -->
    <!-- widget grid -->
    <section id="widget-grid" class="">

        <!-- row -->
        <div class="row">
            <!-- NEW WIDGET START -->
            <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

                <!-- Widget ID (each widget will need unique ID)-->
                <div class="jarviswidget " id="wid-id-0" data-widget-editbutton="false"
                     data-widget-colorbutton="false"
                     data-widget-togglebutton="false"
                     data-widget-deletebutton="false"
                     data-widget-fullscreenbutton="true"
                     data-widget-custombutton="false"
                     data-widget-sortable="false">

                    <%--<header>--%>
                    <%--<span class="widget-icon"> <i class="fa fa-table"></i> </span>--%>
                    <%--<h2>客户信息列表</h2>--%>
                    <%--</header>--%>

                    <!-- widget div-->
                    <div>

                        <!-- widget edit box -->
                        <div class="jarviswidget-editbox">
                            <!-- This area used as dropdown edit box -->

                        </div>
                        <!-- end widget edit box -->

                        <!-- widget content -->
                        <div class="widget-body no-padding">

                            <div class="col-sm-12 col-md-12 col-lg-12">
                                <div class=" ">
                                    <div class="row" id="ajax_knowledge_list_row">

                                        <table id="ajax_knowledge_table" class="table table-striped table-bordered table-hover">
                                        </table>
                                        <div id="ajax_knowledge_list_page">
                                        </div>
                                    </div>

                                </div>
                            </div>
                        </div>
                        <!-- end widget content -->

                    </div>
                    <!-- end widget div -->

                </div>
                <!-- end widget -->

            </article>
            <!-- WIDGET END -->

        </div>

        <!-- end row -->

        <!-- end row -->

    </section>
    <!-- end widget grid -->
</div>


<script type="text/javascript">
    $(function(){
        load_knowledge_jqGrid();
    });
    function load_knowledge_jqGrid(){
        jQuery("#ajax_knowledge_table").jqGrid({
            url:'ajax-knowledge!list.action',
            datatype: "json",
            colNames:['知识大类',"知识小类",'知识标题',"编辑日期","操作","id"],
            colModel:[
                {name:'superType_name',index:'superType', width:120,search:true,sortable:true,
                    searchoptions:{sopt: ["cn"],clearSearch:true}},
                {name:'subType_name',index:'subType', width:80,sortable:true,search:true,
                    searchoptions:{sopt: ["cn"],clearSearch:true}},
                {name:'title',index:'title', width:80,search:false,sortable:false},
                {name:'editdate',index:'modifyDate', search:false,width:200},
                {name:'act',index:'act', width:210,sortable:false,search:false,fixed:true},
                {name:'id',index:'id',search:false,hidden:true},
            ],
            rowNum : 10,
            rowList:[10,20,30],
            pager : '#ajax_knowledge_list_page',
            sortname : '',
            sortorder : "",
            gridComplete:function(){
                var ids=$("#ajax_knowledge_table").jqGrid('getDataIDs');
                for(var i=0;i<ids.length;i++){
                    var cl=ids[i];
                    var rowData = $("#ajax_knowledge_table").jqGrid("getRowData",cl);
                    var de="<button class='btn btn-default' data-original-title='查看' onclick=\"fn_knowledge_read('"+cl+"');\"><i class='fa fa-eye'></i>查看</button>"+" ";
                    var dt = "";
                    if ($("#ajax_knowledge_btn_add").length > 0){
                        dt="<button class='btn btn-default' data-original-title='删除' onclick=\"fn_knowledge_destroy('"+cl+"');\"><i class='fa fa-eye'></i>删除</button>"+" ";
                    }
                    jQuery("#ajax_knowledge_table").jqGrid('setRowData',ids[i],{act:de+dt});
                }

                $(".ui-jqgrid-bdiv").css("overflow-x","hidden");

                jqGridStyle();
            },
            jsonReader: {
                root: "dataRows",
                page: "page",
                total: "total",
                records: "records",
                repeatitems : false
            },
            caption : "<i class='fa fa-arrow-circle-right'></i> 知识共享",
            multiselect : false,
            rownumbers:true,
            gridview:true,
            shrinkToFit:true,
            viewrecords: true,
            autowidth: true,
            height:'auto',
            forceFit:true,
            loadComplete: function() {
            }
        });
        $(window).on('resize.jqGrid', function() {
            jQuery("#ajax_knowledge_table").jqGrid('setGridWidth', $("#ajax_knowledge_list_row").width());
        })
        jQuery("#ajax_knowledge_table").jqGrid('filterToolbar',{searchOperators:false,stringResult:true});

        jQuery("#ajax_knowledge_table").jqGrid('navGrid', "#ajax_knowledge_list_page", {
            edit : false,
            add : false,
            del : false,
            search:false
        });
    };

    //删除
    function fn_knowledge_actions_delete(id){
        fn_delete(id);
    };

    //删除
    function fn_delete(id){
        $.SmartMessageBox({
            title : "<i class='fa fa-minus-square txt-color-orangeDark'></i> <span class='txt-color-orangeDark'><strong>删除</strong></span>",
            content : "确定删除吗？",
            buttons : '[取消][确定]'
        }, function(ButtonPressed) {
            if (ButtonPressed === "确定") {
                var vActionUrl = "<%=path%>/com/ajax-knowledge!delete.action";
                data={keyId:id};
                ajax_action(vActionUrl,data,function(pdata){
                    _show(pdata);
                });
                jQuery("#ajax_knowledge_table").trigger("reloadGrid");
            }
        });
    }

    function fn_knowledge_read(id){
        loadURL("ajax-knowledge!read.action?keyId="+id,$('#content'));
    }

    function fn_knowledge_destroy(id){
        var vActionUrl = "<%=path%>/com/ajax-knowledge!delete.action";
        data={keyId:id};
        ajax_action(vActionUrl,data,{},function(pdata){
            _show(pdata);
        });
        jQuery("#ajax_knowledge_table").trigger("reloadGrid");
    }

    $("#ajax_knowledge_btn_add").off("click").on("click",function(){
        loadURL("ajax-knowledge!input.action",$('#content'));
    });
</script>